24. Solution: While Loops Quiz

Solution: Count By

start_num = 5
end_num = 100
count_by = 2

break_num = start_num
while break_num < end_num:
    break_num += count_by

print(break_num)

Output:

101

Another Example Output:

If we used the same code above, except with these starting values:

start_num = 300
end_num = 548
count_by = 23

This would output:

553

Quiz: Count By Check

start_num = 5
end_num = 100
count_by = 2

if start_num > end_num:
    result = "Oops! Looks like your start value is greater than the end value. Please try again."

else:
    break_num = start_num
    while break_num < end_num:
        break_num += count_by

    result = break_num

print(result)

Output:

101

Another Example Output:

If we used the same code above, except with these starting values:

start_num = 199
end_num = 4
count_by = 10

This would output:

Oops!  Looks like your start value is greater than the end value.  Please try again.

Solution: Nearest Square

limit = 40

num = 0
while (num+1)**2 < limit:
    num += 1
nearest_square = num**2

print(nearest_square)

Output:

36